package ystp.service;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import ystp.dao.ShengchanqiyelinxuantoupiaoMapper;
import ystp.model.Shengchanqiyelinxuantoupiao;
import ystp.model.ShengchanqiyelinxuantoupiaoExample;

import javax.annotation.Resource;

@Service
public class ShengchanqiyelinxuantoupiaoService {

    @Resource
    public ShengchanqiyelinxuantoupiaoMapper ddMapper;

    public Shengchanqiyelinxuantoupiao checkexistByUserId(String ppId, String ppUserId){
        ShengchanqiyelinxuantoupiaoExample mmExample=new ShengchanqiyelinxuantoupiaoExample();
        mmExample.createCriteria().andDetailidEqualTo(ppId).andUseridEqualTo(ppUserId);
        return ddMapper.selectByExample(mmExample).size()>0? ddMapper.selectByExample(mmExample).get(0): null;
    }

    public boolean add(Shengchanqiyelinxuantoupiao ppShengchanqiyelinxuantoupiao){
        return ddMapper.insert(ppShengchanqiyelinxuantoupiao)==1;
    }

    public boolean modify(Shengchanqiyelinxuantoupiao ppShengchanqiyelinxuantoupiao){
        return ddMapper.updateByPrimaryKey(ppShengchanqiyelinxuantoupiao)==1;
    }

    public int countPingguiPass(String ppPingui,String ppUserId){
        ShengchanqiyelinxuantoupiaoExample mmExample=new ShengchanqiyelinxuantoupiaoExample();
        mmExample.createCriteria().andPinguiEqualTo(ppPingui).andUseridEqualTo(ppUserId).andResultEqualTo("1");
        return ddMapper.countByExample(mmExample);
    }

    public int countDetailPass(String ppDetail,String ppUserId,int ppLunci){
        ShengchanqiyelinxuantoupiaoExample mmExample=new ShengchanqiyelinxuantoupiaoExample();
        mmExample.createCriteria().andDetailidEqualTo(ppDetail).andUseridEqualTo(ppUserId).andLunciEqualTo(ppLunci).andResultEqualTo("1");
        return ddMapper.countByExample(mmExample);
    }

    public int countJicaiPass(String ppXiangmuId,String ppUserId){
        Object mmCount = ddMapper.countJicaiPass(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public int countPass(String ppXiangmuId,String ppUserId){
        Object mmCount = ddMapper.countPass(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public int countPinguiPass(String ppXiangmuId,String ppPingui,String ppUserId,int ppLunci){
        Object mmCount = ddMapper.countPinguiPass(ppXiangmuId,ppPingui,ppUserId,ppLunci);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public int getOneScore(String ppDetailId,int ppLunci){
        ShengchanqiyelinxuantoupiaoExample mmExample=new ShengchanqiyelinxuantoupiaoExample();
        mmExample.createCriteria().andDetailidEqualTo(ppDetailId).andLunciEqualTo(ppLunci).andResultEqualTo("1");
        return ddMapper.countByExample(mmExample);
    }
}
